home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_08 / 9n08102a < prev    next >
Text File  |  1991-06-04  |  1KB  |  69 lines

  1.  
  2. #include <bios.h>
  3. #include <stdio.h>
  4.  
  5. #define SIZE_FIELD 10
  6.  
  7. struct s_test 
  8.     {
  9.     int filler;
  10.     char field[SIZE_FIELD];
  11.     };
  12.     
  13. struct s_test test_structure = {1, "TESTFIELD"};
  14. struct s_test *structure_pointer = &test_structure;
  15. char *char_pointer = test_structure.field;
  16.  
  17. #define REPEAT_LIMIT 100000L
  18.  
  19. time_function(p_function)
  20. int (*p_function)();
  21.     {
  22.     long start_time, stop_time;
  23.     long l;
  24.         
  25.     _bios_timeofday(_TIME_GETCLOCK, &start_time);
  26.  
  27.     for (l=0; l < REPEAT_LIMIT; l++)
  28.         {
  29.         (*p_function)();
  30.         }
  31.             
  32.     _bios_timeofday(_TIME_GETCLOCK, &stop_time);
  33.     
  34.     printf("\n Elapsed time %ld start %ld stop %ld repetitions %ld",
  35.         stop_time - start_time, start_time, stop_time, REPEAT_LIMIT);
  36.     }
  37.     
  38. dummy_function(pointer)
  39. void *pointer;
  40.     {
  41.     return;
  42.     }
  43.  
  44. access_with_char_pointer()
  45.     {
  46.     char *cp;
  47.     cp = char_pointer;
  48.     dummy_function(cp);
  49.     }
  50.  
  51. access_with_structure_pointer()
  52.     {
  53.     char *cp;
  54.     cp = structure_pointer->field;
  55.     dummy_function(cp);
  56.     }
  57.  
  58. main()
  59.     {
  60.     printf("\n Dummy function");
  61.     time_function(dummy_function);
  62.     
  63.     printf("\n access_with_char_pointer");
  64.     time_function(access_with_char_pointer);
  65.     
  66.     printf("\n access_with_structure_pointer");
  67.     time_function(access_with_structure_pointer);
  68.     }
  69.